package com.scau.dao.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.scau.dao.AdminDao;
import com.scau.mapper.AdminMapper;
import com.scau.pojo.Admin;
import com.scau.util.SqlSessionFactoryUtil;
@Repository
public class AdminDaoImpl implements AdminDao{
	
	SqlSession session = SqlSessionFactoryUtil.getSession();
	AdminMapper adminMapper=session.getMapper(AdminMapper.class);
	
	@Override
	public List<Admin> getAllAdmin(){
		return adminMapper.selectByExample(null);
	}

	@Override
	public Map<String,Object> getAdmin(String name) {
		Map<String,Object> result=new HashMap<String,Object>();
		try {
			Admin admin=adminMapper.selectByName(name);
			if(admin!=null){
				result.put("admin", admin);
			}else{
				result.put("admin", null);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public int update(Admin admin) {
		
		return adminMapper.updateByPrimaryKeySelective(admin);
	}
}
